home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tvdmx.exe / SAMPLES.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-16  |  25KB  |  820 lines

  1.  
  2. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  3. {                            }
  4. {    SAMPLES   --Multi-window sample demo program    }
  5. {    tvDMX     --data editing project (ver 1.5)    }
  6. {                            }
  7. {    Copyright (c) 1992  Randolph Beck        }
  8. {                P.O. Box  56-0487        }
  9. {                Orlando, FL 32856        }
  10. {                CIS:  72361,753        }
  11. {                            }
  12. {■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
  13.  
  14. Program SAMPLES;
  15.  
  16. { This program was written to demonstrate various data structures.  You can
  17.   examine the field templates and copy some portions into WORKSHOP.PAS for
  18.   your own experiments.
  19.  
  20.   The design of some of these record structures may seem pointless since
  21.   they are intended only to demonstrate the interface mechanism.
  22.  
  23.   The "Account" window is the simplest example here.  It's somewhat bland,
  24.   but most programmers will only require simple data structures like this.
  25.  
  26.   The "Payroll" window is a larger data window.  It demonstrates the 'Z'
  27.   template code, which forces the display of leading zeroes in that field.
  28.   Its last three fields are marked as READ-ONLY (with the ^R code).  These
  29.   are entered automatically by the virtual methods in object TDmxPayroll,
  30.   which overrides TDmxEditor.
  31.  
  32.   The "Busy" window uses a more complex template string.  Note the heavy use
  33.   of control codes, and that the last field in the main window is Read-Only.
  34.   One of the integer fields is marked as a "skip" field (that means that the
  35.   cursor will not land on it).
  36.  
  37.   The DateTime type is used here, with fldDATETIME, fldDATE, and fldTIME
  38.   constants --as defined in the DMXGIZMA unit.  Its Year, Month and Day are
  39.   swapped by codes in the fldDATETIME and fldDATE string to place it in its
  40.   more familiar Month-Day-Year order.
  41.  
  42.  
  43.   Two other views are available from the menu:  "Hex" is a tvDMX-driven
  44.   hex-byte editor using the same data as Busy window;  and "Dialog" is a
  45.   dialog box that uses tvDMX descendants for individual field input, using
  46.   the data in the current window at the current record.  A dialog window
  47.   may also be actuated by double-clicking a record with a mouse.
  48.  
  49.   The data in most windows can be reported to file SAMPLES.OUT, using the
  50.   objects in unit tvDMXREP.PAS.
  51.  
  52.   (See file TVDMXHEX.PAS for the code used in the hexadecimal byte editor.)
  53.  }
  54.  
  55. {$V-,X+ }
  56.  
  57. uses
  58.     Dos, { required to define DateTime type }
  59.     Objects, Drivers, Views, Menus, Dialogs, App, MsgBox,
  60.     RSet, DmxGizma, tvDMX, StdDMX, tvDmxHex, tvDmxRep, tvGizma;
  61.  
  62. const
  63.     ReportName    =  'SAMPLES.OUT';
  64.  
  65.     cmHasDialog   =  103;
  66.  
  67.     cmAccounts    =  111;
  68.     cmPayroll     =  112;
  69.     cmBusyWin     =  113;
  70.     cmHexWin      =  114;
  71.     cmDialog      =  115;
  72.     cmRecDialog   =  116;
  73.     cmReport      =  117;
  74.  
  75.     cmNoCmd       = 1000;
  76.  
  77.     hcMenus       = 1000;
  78.     hcDeskTop     = 1100;
  79.     hcAccounts    = 1100;
  80.     hcPayroll     = 1200;
  81.     hcBusyWin     = 1300;
  82.     hcHexWin      = 1400;
  83.     hcDialogs     = 4000;
  84.  
  85.  
  86.       { Data presentation template for the "Accounts" window.
  87.         The data structure is declared as "TAccount" in the TYPE section.
  88.        }
  89.  
  90.     AccountLabel : string =
  91.     ' Transaction          Debit        Credit      [?] ';
  92.  
  93.     AccountInfo  : string =
  94.     ' SSSSSSSSSSSSSSSS| rrr,rrr.rr  | rrr,rrr.rr  | [x] ';
  95.  
  96.  
  97.  
  98.       { Data presentation template for the "Payroll" window.
  99.     The data structure is declared as "TPayroll" in the TYPE section.
  100.     The last three fields are marked READ-ONLY, and are automatically
  101.     entered by the virtual methods in object TDmxPayroll.
  102.        }
  103.  
  104.     _PayrollLabel = ' Employee                ID     Earnings       FICA        FITW        SITW   ';
  105.     _PayrollInfo  = ' ssssssssssssssssssssss| ZZW ║ $rr,rrr.rr | $r,rrr.rr '^R'| $r,rrr.rr '^R'| $r,rrr.rr '^R;
  106.  
  107.     PayrollLabel  :  string [length (_PayrollLabel)]  =  _PayrollLabel;
  108.     PayrollInfo   :  string [length (_PayrollInfo)]   =  _PayrollInfo;
  109.  
  110.  
  111.  
  112.       { This next screen will be a bit busy, but I wanted to implement many
  113.     of the special options.  I thought it might be easier to decipher
  114.     all this by separating the field-strings into one field per line.
  115.     Each line (except the first) begins with a field delimiter.
  116.     The data structure is declared as "TBusyData" in the TYPE section.
  117.        }
  118.  
  119.     _BusyLabel    =
  120.     ' Name                    SSN             Balance     Start Date   Time   <A>  [B]   Pointer       Value     RO ';
  121.  
  122.     _BusyInfo     =   'B' + ^H        { hidden byte field }
  123.             + #0' ssssssssssssssssssssss'  { Name field }
  124.             + '| ###-##-#### '    { string of numerics only }
  125.             + '|r,rrr,rrr    '    { positive or negative }
  126.  
  127.            { DateTime type: }
  128.             + '|' + fldDATE    { untyped constants }
  129.             + #0  + fldTIME    { defined in DMXGIZMA.PAS }
  130.  
  131.             + '|iii ' + ^Z^R^S    { showzeroes/readonly/skip }
  132.             + '\iii '        { normal integer }
  133.             + '| HHHH:HHHH '    { hex longint value }
  134.             + '|RRR,RRR.RRR '    { positive values only }
  135.             + '| hh ' + ^Z^R;    { showzeroes/readonly field }
  136.  
  137.  
  138.     BusyInfo      :  string [length (_BusyInfo)]  =  _BusyInfo;
  139.     BusyLabel     :  string [length (_BusyLabel)] =  _BusyLabel;
  140.  
  141.  
  142.     MaxRecordNum  =   29;
  143.  
  144.  
  145.  
  146. type
  147.     PAccount      = ^TAccount;
  148.     PPayroll      = ^TPayroll;
  149.     PBusyData     = ^TBusyData;
  150.  
  151.  
  152.     TAccount      =  RECORD
  153.     Account    :  string [16];
  154.     Debit    :  real;
  155.     Credit    :  real;
  156.     Status    :  boolean;
  157.     end;
  158.  
  159.  
  160.     TPayroll      =  RECORD
  161.     Employee :  string [22];
  162.     ID       :  word;
  163.     Earnings :  real;
  164.     FICA     :  real;  { READ-ONLY }
  165.     FITW     :  real;  { READ-ONLY }
  166.     SITW     :  real;  { READ-ONLY }
  167.     end;
  168.  
  169.  
  170.     TBusyData     =  RECORD
  171.     Marker        :  byte;    { HIDDEN field }
  172.     Name        :  string [22];
  173.     SSN        :  string [9];
  174.     realfield1    :  real;
  175.     DT        :  datetime;
  176.     intfield0    :  integer;    { READ-ONLY }
  177.     intfield1    :  integer;
  178.     ptrfield    :  pointer;
  179.     realfield2    :  real;
  180.     hextwo        :  byte;    { READ-ONLY }
  181.     end;
  182.  
  183.  
  184.     PDmxEditTbl     = ^TDmxEditTbl;
  185.     PDmxEditTblWin  = ^TDmxEditTblWin;
  186.  
  187.  
  188.     TDmxEditTbl     =  OBJECT (TDmxEditor)
  189.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  190.     end;
  191.  
  192.  
  193.     TDmxEditTblWin  =  OBJECT (TDmxWindow)
  194.       procedure InitDMX (ATemplate : string;  var AData;
  195.                          ALabels, ARecInd : PDmxLink;
  196.                          BSize  : longint);  VIRTUAL;
  197.     end;
  198.  
  199.  
  200.     PDmxPayroll    = ^TDmxPayroll;
  201.     PDmxPayrollWin = ^TDmxPayrollWin;
  202.  
  203.  
  204.     TDmxPayroll    =  OBJECT (TDmxEditTbl)
  205.       procedure EvaluateField;  VIRTUAL;
  206.       procedure ZeroizeField (Whole :boolean; Field :pDMXfieldrec);  VIRTUAL;
  207.       procedure RecalcRecord;
  208.     end;
  209.  
  210.  
  211.     TDmxPayrollWin =  OBJECT (TDmxWindow)
  212.       procedure InitDMX (ATemplate : string;  var AData;
  213.                          ALabels, ARecInd : PDmxLink;
  214.                          BSize  : longint);  VIRTUAL;
  215.     end;
  216.  
  217.  
  218.     PMyStatusLine  = ^TMyStatusLine;
  219.     TMyStatusLine  =  OBJECT (TStatusLine)
  220.       function  Hint (AHelpCtx : word) : string;  VIRTUAL;
  221.     end;
  222.  
  223.  
  224.     TAppN          =  OBJECT (TAppA)
  225.     end;
  226.  
  227.  
  228.     TMyApp         =  OBJECT (TAppN)
  229.       constructor Init;
  230.       procedure Idle;  VIRTUAL;
  231.       procedure HandleEvent (var Event : TEvent);  VIRTUAL;
  232.       procedure InitMenuBar;     VIRTUAL;
  233.       procedure InitStatusLine;  VIRTUAL;
  234.       procedure AccountWindow;
  235.       procedure PayrollWindow;
  236.       procedure BusyWindow;
  237.       procedure HexWindow;
  238.       procedure AccountDialog (P : PDmxEditTbl);
  239.       procedure PayrollDialog (P : PDmxPayroll);
  240.       procedure BusyDialog (P : PDmxEditTbl);
  241.     end;
  242.  
  243.  
  244. var
  245.     Accounts   :  array [0..49] of TAccount;
  246.     Payroll    :  array [0..49] of TPayroll;
  247.     BusyData   :  array [0..MaxRecordNum] of TBusyData;
  248.  
  249.  
  250.   procedure InitializeData;  forward;  { for the sample data }
  251.  
  252.  
  253.   { ══ TMyStatusLine ═════════════════════════════════════════════════════ }
  254.  
  255.  
  256. function  TMyStatusLine.Hint (AHelpCtx : word) : string;
  257. begin
  258.   Case AHelpCtx of
  259.     hcDragging:  Hint := #24#25#26#27' Move  Shift-'#24#25#26#27' Resize  '#17#196#217' Done  Esc Cancel';
  260.    else          Hint := '';
  261.     end;
  262. end;
  263.  
  264.  
  265.   { ══ TDmxEditT